<?php
/**
 * Пейджер
 * 
 * Класс для отображения нумератора страниц
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Класс для отображения нумератора страниц
 *
 */
class Pagination extends Base {
	public $totall;
	public $page;
	public $show_limit;
	public $max;
	public $prev;
	public $next;
	public $pages;
	public $split=9;
	public $split_pages;
	/**
	 * Констуктор
	 *
	 * @param string $className имя роутера
	 */
	public function __construct($totall,$page,$show_limit){		
		parent::__construct(__CLASS__);
		$this->totall=$totall;
		$this->page=$page;
		$this->show_limit=$show_limit;
		$this->max=ceil($this->totall/$this->show_limit);
		$this->pages=$this->buildPages();
		$this->split_pages=$this->buildPages($this->split);
		$this->prev=$this->page>1?$this->page-1:1;
		$this->next=$this->page<$this->max?$this->page+1:$this->max;
		$this->countPages=count($this->pages);
		$this->show=$this->countPages>1;
	}
	
	public function buildPages($split=false){
	    if(!$this->totall)return array(1);
		$return=array();
		$start=$split?$this->page-floor($split/2):1;
		$start=$start>0?$start:1;
		$end=$split?$start+$split-1:$this->max;
		if($end<$start){
		    new CoreExeption('Неправильные параметры',E_ERROR,__FILE__,__LINE__,array('totall'=>$this->totall,'page'=>$this->page,'show_limit'=>$this->show_limit,'split'=>$split,'end'=>$end,'statr'=>$start));
		}
		for ($i=$start;$i<=$end;$i++){
			$return[]=$i;
		}
		return $return;
	}
}